package model.commands;

import model.GameConstants;
import model.IModel;
import ctf.model.Side;
import ctf.network.ProtocolError;

public class AcceleratePlayerCommand extends AbstractModelCommand {

	private float newAcceleration;
	private int playerNum;
	private Side side;

	public AcceleratePlayerCommand(int executionTimeInMs, Side side,
			int playerNum, float newAcceleration) {
		super(executionTimeInMs);
		this.side = side;
		this.playerNum = playerNum;
		this.newAcceleration = newAcceleration;
	}
	
	@Override
	public void checkValid(IModel model) throws ProtocolError {
		if (newAcceleration > GameConstants.MAXIMUM_PLAYER_ACCELERATION
				|| newAcceleration < GameConstants.MINIMUM_PLAYER_ACCELERATION) {
			throw new ProtocolError("Expected player acceleration in ("
					+ GameConstants.MINIMUM_PLAYER_ACCELERATION + ","
					+ GameConstants.MAXIMUM_PLAYER_ACCELERATION + ")", Float
					.toString(newAcceleration));
		}
		if (model.playerExists(side, playerNum) == false) {
			throw new ProtocolError("Expected player on side "
					+ side.toString(), "No player in side "
					+ side.toString());
		}
	}

	@Override
	public void execute(IModel model) {
		model.acceleratePlayer(side, playerNum, newAcceleration);
	}

	
}
